#!/bin/sh

error() {
	echo "Error: Ooooops.... did you change the code hum? :("
	echo
	exit 1
}

# Assembly calling syscalls direct
nasm -felf hello.asm
if [ -f "hello.o" ]; then
	ld hello.o -o hello
	
	if [ -f "hello" ]; then
		echo "Hello World in assembly ok!"
		rm hello.o
	fi
else
	error
fi

# C
gcc helloc.c -o helloc
if [ -f "helloc" ]; then
	echo "Hello World in C ok!"
else
	error
fi

# Assembly using libc
nasm -felf hello_libc.asm
if [ -f "hello_libc.o" ]; then
	gcc hello_libc.o -o hello_libc
	
	if [ -f "hello" ]; then
		echo "Hello World in assembly using libc ok!"
		rm hello_libc.o
	fi
else
	error
fi

echo "Okay.... everything seems good... now try to use strace like this:"
echo
echo "strace ./hello"
echo
echo "strace ./helloc"
echo
echo "strace ./hello_libc"


